package com.qclix.inv;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Pierre Moermans
 */
public class Contract {
    private static final long serialVersionUID = 1L;
    
    private String reference;
    private Client client;
    private Date validFrom;
    private Date validTill;
    private float hourlyRate;
    private Set<Invoice> invoices;

    public Set<Invoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(Set<Invoice> invoices) {
        this.invoices = invoices;
    }

    public Contract() {
        setInvoices(new HashSet<Invoice>());
    }

    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public Client getClient() {
        return client;
    }

    public void setClient(Client client) {
        this.client = client;
    }

    public Date getValidFrom() {
        return validFrom;
    }

    public void setValidFrom(Date validFrom) {
        this.validFrom = validFrom;
    }

    public Date getValidTill() {
        return validTill;
    }

    public void setValidTill(Date validTill) {
        this.validTill = validTill;
    }

    public float getHourlyRate() {
        return hourlyRate;
    }

    public void setHourlyRate(float hourlyRate) {
        this.hourlyRate = hourlyRate;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("Contract[reference=").append(getReference());
        builder.append(", client=").append(getClient().getName());
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        builder.append(", valid from=").append(sdf.format(getValidFrom()));
        if (getValidTill() != null) {
            builder.append(", valid till=").append(sdf.format(getValidTill()));
        } else {
            builder.append(", no end date");
        }
        builder.append(", hourly rate=").append(getHourlyRate());
        builder.append("]");
        return builder.toString();
    }
}
